<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * 
 */
class Price_range_model extends MY_Model
{
    public function __construct()
    {
        parent::__construct();
        $this->_table = "price_range"; // Overr ide teh setting of the table name
    }

    /**
     *get all in sort by min value
     */
    public function getall() {
        $sql = "SELECT * FROM ".$this->_table." ORDER BY ?"; 
        $this->db->order_by('min', 'ASC');
        return $this->db->get($this->_table)->result();
    }
    /**
     * 
     * @param array $data list of data to sate
     * @return boolean
     */
    public function save($data = array())
    {
        log_message("info", print_r($data, true));
        try{
            $id = (int)$data['id'];
            unset($data['id']);
            if ($id>0){
                log_message("info", "UPDATE");
                return $this->update($id, $data);
            }else{
                log_message("info", "INSERT");
                return $this->insert($data);
            }
        }  catch (Exception $e){
            log_message("error", "[PR] - ".$e->getMessage());
            return false;
        }
    }
}